﻿using CatUtils.Utils.Currency.IoUtils;
using CatUtils.Utils.Helper;
using CatUtils.Utils.SpecialUtils.PicBed.Sina;
using SinaImgUpload.SainTool.Configuration;
using SinaImgUpload.SainTool.DataEnhance.Sqlite;
using SinaImgUpload.SainTool.SinaLogin;
using SinaImgUpload.UserView.ServerTool;
using SinaImgUpload.UserView.ViewHelper;
using System;
using System.Text;
using System.Windows.Forms;

namespace SinaImgUpload
{
    public partial class MainView : Form
    {
        public MainView()
        {
            InitializeComponent();
            InitView(new string[0]);
        }

        public MainView(String[] RunData)
        {
            InitializeComponent();
            InitView(RunData);
        }

        private void InitView(String[] RunData)
        {
            comboBox1.Items.AddRange(GroupBoxHelper.ModeList.ToArray());
            comboBox1.SelectedIndex = 0;
            new PicBedManger().InitSqllite();
            new ConfigurationHelper().InitInfo();
            if (RunData.Length > 0)
            {
                new UploadBatch().UploadFile(RunData);
                System.Environment.Exit(0);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //  Console.WriteLine(SinaUpload.SinaImg.UploadSingle(SelectHelper.SelectFile()));
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FloderHelper.OpenFloder(".\\");
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string FloderName = "/list";
            string UploadFileCommend = $"bypy mkdir {FloderName}";

            FileHelper.WriteText($"{StaticValue.TempPath}rundir.bat", UploadFileCommend, Encoding.ASCII);
            FloderHelper.OpenFloder($"{StaticValue.TempPath}rundir.bat");
            FileHelper.WriteText($"{StaticValue.TempPath}rundir.bat", UploadFileCommend, Encoding.ASCII);
            FloderHelper.OpenFloder($"{StaticValue.TempPath}rundir.bat");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            SinaImgUploadTool.InitSecurity();
            PicBedHelper.CheckSinaLogin();
            Console.WriteLine("test upload:" + SinaImgUploadTool.UploadImgLink("http://ww2.sinaimg.cn/orj360/006rcAdrgy1fvuuap85uaj30m80pljtw.jpg")); ;
        }

        private void button10_Click(object sender, EventArgs e)
        {
            new SinaLoginForm("https://weibo.com/").Show();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            new GroupBoxHelper().AutoReplace(groupBox1, comboBox1.Text);
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            new UserInfo().ShowDialog();
        }
    }
}